<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class EditAction extends BaseAccountAction {

	//修改邮箱
	public function index() {
		$this->init();
		$uid = Session::get('user_id');
		if (!empty($uid)) {
			$User = D('User');
			$data = $User->relation("school")->where("user_id=" . $uid)->find();
			$this->assign('profile', $data);
			$this->display();
		} else {
			$this->error('请先登录!');
		}
	}

	//修改手机
	public function saveMobile() {
		
	}

	//发送验证码
	public function sendVerify() {
		
	}

	//修改邮箱
	public function saveEmail() {
		$uid = Session::get('user_id');
		$password = $_POST["password"];
		$email = trim($_POST["email"]);
		$reemail = trim($_POST["reemail"]);
		$email != $reemail && $this->ajaxReturn(null, array("email" => "输入的邮箱不一致"), -1);
		empty($password) && $this->ajaxReturn(null, array("password" => "请输入密码"), -5);
		if (!empty($email) && !Model::regex($email, "email"))
			$this->ajaxReturn(null, array("email" => "邮箱格式错误"), -2);
		$User = D("User");
		$oldPassword = $User->where("user_id=" . $uid)->getField("password");
		if (empty($oldPassword))
			$this->ajaxReturn(null, array("email" => "账号不存在"), -3);
		if ($oldPassword != md5($password))
			$this->ajaxReturn(null, array("password" => "密码错误"), -4);
		//更新邮箱
		$User->user_id = $uid;
		$User->email = $email;
		$user = $User->save();
		$this->ajaxReturn($user, "修改成功", 1);
	}

}

?>
